<template>
	<view class="infomation">
		<view class="my_order">
			<view class="order_title cover" @click="Click('头像')">
				<view class="title_left">头像</view>
				<view class="title_right ">
					<image :src="'https://qiniu.feelmao.com/'+avater||content.avater" class="top_cover"></image>
					</view>
			</view>
			<view class="order_title" @click="Click('昵称')">
				<view class="title_left">昵称</view>
				<view class="title_right ">{{ content.nickname }}</view>
			</view>
			<view class="order_title" @click="Click('简介')">
				<view class="title_left">简介</view>
				<view class="title_right ">{{ content.introduction||'介绍一下自己' }}</view>
			</view>
			<view class="order_title title_id" @click="Click('用户')">
				<view class="title_left">用户ID</view>
				<view class="title_right ">{{ content.uuid }}</view>
			</view>
			<view class="order_title" @click="Click('性别')">
				<view class="title_left">性别</view>
				<view class="title_right ">{{ content.sex }}</view>
			</view>
			<view class="order_title" @click="Click('二维码')">
				<view class="title_left">二维码</view>
				<view class="title_right "><image src="/pagesB/static/QRcode_white@2x.png" class="top_ewm"></image></view>
			</view>
			<view class="order_title" @click="Click('微信号')">
				<view class="title_left">微信号</view>
				<view class="title_right ">{{ content.weixin == 1 ? '已绑定' : '未绑定' }}</view>
			</view>
			<view class="order_title" @click="Click('手机号绑定')">
				<view class="title_left">手机号绑定</view>
				<view class="title_right ">{{ content.phone }}</view>
			</view>
			<view class="order_title" @click="Click('收货地址管理')">
				<view class="title_left">收货地址管理</view>
				<view class="title_right "></view>
			</view>
		</view>
<!-- 		<uni-popup ref="popup" type="center">
			<uni-popup-dialog type="dialog" title="解除绑定" content="是否解除微信关联" @confirm="confirm" duration="0"></uni-popup-dialog>
		</uni-popup>
		<uni-popup ref="popups" type="center">
			<uni-popup-dialog type="dialog" title="绑定微信" content="是否关联当前微信" @confirm="confirm1" duration="0"></uni-popup-dialog>
		</uni-popup> -->
	</view>
</template>

<script>
import md5 from '@/common/api/md5.js'
import {requestUrl} from '@/common/config.js'
import uniPopup from '@/components/uni-popup/uni-popup.vue'
import uniPopupMessage from '@/components/uni-popup/uni-popup-message.vue'
import uniPopupDialog from '@/components/uni-popup/uni-popup-dialog.vue'
export default {
	    components: {
	        uniPopup,
	        uniPopupMessage,
	        uniPopupDialog
	    },
	data() {
		return {
			access_token:'',
			content:'',
			Code:'',
			Url:'',
			avater:''
		};
	},
	onShow() {
		this.$request('/app/upload/getUploadConfig','post',{
			access_token:uni.getStorageSync('access_token').replace(/^\"|\"$/g,''),
		}).then(res=>{
			console.log(res)
			this.Url=res.content
		})
				if(uni.getStorageSync('access_token')){
				this.access_token=JSON.parse(uni.getStorageSync('access_token'))
				}else{
					uni.showModal({
					    title: '提示',
					    content: '你还未登录，请先登录',
					    success: function (res) {
					        if (res.confirm) {
								uni.navigateTo({
									url:'/pages/login/login'
								})
					        } else if (res.cancel) {
					        }
					    }
					});
				}
		let time = Math.round(new Date().getTime() / 1000).toString()
		let _this = this
		let Time = ['time', time].join('=')
		let Access_token = ['access_token', this.access_token].join('=')
		let content = ['content=pinet.FeiMao.2017'].join()
		let arr = [content, Time].sort(function(a, b) {
			a - b
		})
		let newarr = md5(arr.join('&'))
		uni.request({
			url: requestUrl+'/app/user/getUserInfo',
			method: "GET",
			data: {
				access_token: this.access_token,
				time: time,
				sign: newarr
			},
			success: function(res) {
				if(res.data.errcode==0){
					_this.content=res.data.content
				}
			}
		});
	},
	methods:{
		Click(e){
			console.log(e)
			let _this = this
			if(uni.getStorageSync('access_token')){
			this.access_token=JSON.parse(uni.getStorageSync('access_token'))
			}else{
				uni.navigateTo({
				    url: '/pages/login/login'
				});
			}
			let time = Math.round(new Date().getTime() / 1000).toString()
			let Time = ['time', time].join('=')
			let Access_token = ['access_token', this.access_token].join('=')
			let content = ['content=pinet.FeiMao.2017'].join()
			let arr = [content, Time].sort(function(a, b) {
				a - b
			})
			let newarr = md5(arr.join('&'))
			if(e=='头像'){
						let that = this;
						uni.chooseImage({ // 从本地相册选择图片或使用相机拍照。
							 count:1,
						        sizeType: ['original', 'compressed'],
						        sourceType: ['album', 'camera'],
						        success: function(res) {
						          var img = res.tempFilePaths;
						          console.log(img)
						          wx.showToast({
						            icon: "loading",
						            title: "上传图片中..."
						          });
								that.$UploadImg(res.tempFilePaths[0],_this.Url.token).then(res=>{
									console.log(res.key)
									that.$request('/app/user/changeAvater','post',{	
										access_token:uni.getStorageSync('access_token').replace(/^\"|\"$/g,''),
										avater:res.key
									}).then(res=>{
										console.log(res.content)
										that.avater=res.content
										console.log(that.avater,'1212121')
									})
								})
								
							}
						});
						//     let that=this;
						//       wx.chooseImage({
						//         count:1,
						//         sizeType: ['original', 'compressed'],
						//         sourceType: ['album', 'camera'],
						//         success: function(res) {
						//           var img = res.tempFilePaths;
						//           console.log(img)
						//           wx.showToast({
						//             icon: "loading",
						//             title: "上传图片中..."
						//           });
						//           // 将本地资源上传到服务器。客户端发起一个 HTTPS POST 请求，其中 content-type 为 multipart/form-data
						//           wx.uploadFile({
						//             url: requestUrl + '/app/user/changeAvater', //接口
						//             filePath: img[0],
						//             header:{token:that.data.token},
						//             name: 'file',
						//             formData: {
						// 				access_token:uni.getStorageSync('access_token').replace(/^\"|\"$/g,''),
						//             },
						//             success: function (res) {
						//               var data = JSON.parse(res.data);
						//               console.log(res.data)
						//               //do something
						//               if(data.code=='200'){
						//                 that.setData({xztx:imgUrl+data.data,xztxt:data.data})
						//               }
				// uni.chooseImage({
				//     count: 1, //默认9
				//     success: function (res) {
				//         console.log(res);
				// 		let image =  res.tempFilePaths[0]
				// 		console.log(image)
				// 		_this.$request('/app/user/changeAvater','post',{
				// 			access_token:uni.getStorageSync('access_token').replace(/^\"|\"$/g,''),
				// 			avater:image
				// 		}).then(res=>{
				// 			// this.tabList=[...this.tabList,...res.content]
				// 		})
						// uni.request({
						// 	url: requestUrl+'/app/user/changeAvater',
						// 	method: "GET",
						// 	data: {
						// 		access_token: _this.access_token,
						// 		time: time,
						// 		sign: newarr,
						// 	},
						// 	success: function(res1) {
						// 		console.log(res1)
						// 		// if(res.data.errcode==0){
						// 		// 	_this.content=res.data.content
						// 		// }
						// 	}
						// });
				    // }
				// });
			}else if(e=='昵称'){
				uni.navigateTo({
					url:'/pagesB/information/nickname?name='+this.content.nickname
				})
			}else if(e=='用户'){
				console.log('用户')
			}else if(e=='简介'){
				uni.navigateTo({
					url:'/pagesB/information/modifyintroduction?content='+this.content.introduction
				})
			}else if(e=='性别'){
				uni.navigateTo({
					url:'/pagesB/information/modifysex'
				})
			}else if(e=='二维码'){
				uni.navigateTo({
					url:'/pagesB/ewm/ewm'
				})
			}else if(e=='微信号'){
				// if(this.content.weixin==1){
				// 	this.$refs.popup.open()
				// }else{
				// 	this.$refs.popups.open()
				// }
			}else if(e=='手机号绑定'){
				uni.navigateTo({
					url:'/pagesB/information/modifyphone'
				})
			}else if(e=='收货地址管理'){
				uni.navigateTo({
					url:'/pagesA/management/management'
				})
			}
		}
	}
}
</script>

<style lang="less">
.infomation {
	height: 100%;
	background-color: #f3f4f5;
	.my_order {
		background: #fff;
		margin-bottom: 20rpx;

		.order_title {
			display: flex;
			justify-content: space-between;
			padding: 20rpx 40rpx;
			border-bottom: 1px solid #eeeeee;
			background: url(@/static/direction_right_gray.png) no-repeat 690rpx 22rpx;
			background-size: 28rpx 28rpx;
			.title_left {
				font-size: 28rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #9da5a8;
			}
			.title_right {
				font-size: 24rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #111;
				padding-right: 30rpx;
				.top_ewm {
					width: 40rpx;
					height: 40rpx;
					margin: auto;
				}
				.top_cover {
					width: 120rpx;
					height: 120rpx;
					border-radius: 50px;
				}
			}
		}
		.cover {
			background: url(@/static/direction_right_gray.png) no-repeat 690rpx 70rpx;
			background-size: 28rpx 28rpx;
			align-items: center;
		}
		.title_id {
			background: none;
			.title_right {
				padding: 0;
			}
		}
	}
}
</style>
